package com.xd.core.business.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xd.common.util.AESUtil;
import com.xd.common.util.MD5Util;
import com.xd.core.business.entity.CarCredit;
import com.xd.core.business.service.ICarCreditService;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TreeMap;

@Slf4j
@NoArgsConstructor
public class ImportCarCreditListener extends AnalysisEventListener<CarCredit> {

    private static int vipCount;
    private ICarCreditService carCreditService;
    private static final int MAX_LIST_SIZE = 20;
    private Integer incomingId;
    private List<CarCredit> list = new ArrayList<>();
    private TreeMap<String, Integer> map = new TreeMap<>();
    private int count = 0;//总共导入数量


    public ImportCarCreditListener(ICarCreditService carCreditService ,Integer incomingId) {
        this.carCreditService = carCreditService;
        this.incomingId = incomingId;
    }



    @Override
    public void invoke(CarCredit carCredit, AnalysisContext analysisContext) {
        count++;
        list.add(carCredit);
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        map = carCreditService.importCarCreditListener(list,incomingId);
        map.put("导入数据",count);
        log.info("excel数据导入完成");
    }

    public TreeMap<String, Integer> getMap(){
        return this.map;
    }
}
